//package com.Exam;
//
//import java.util.*;
//
//public class Exam02 {
//    //给定两个字符串 `s` 和 `t` ，编写一个函数来判断 `t` 是否是 `s` 的字母异位词。
//    // s = "anagram", t = "nagaram"
//    public static void main(String[] args) {
//        String str1 = "reeffdi";
//        String str2 = "differe";
//        Exam02 e2 = new Exam02();
//        System.out.println(e2.different(str1, str2));
//    }
//
//    public boolean different(String str1,String str2){
//        ArrayList<Character> arrayList = new ArrayList<>();
//        for (int i = 0; i <str1.length() ; i++) {
//            arrayList.add(str1.charAt(i));
//        }
//        for (int i = 0; i <str2.length() ; i++) {
//            arrayList.add(str2.charAt(i));
//        }
//        arrayList.sort(new Comparator<Character>() {
//            @Override
//            public int compare(Character o1, Character o2) {
//                return o1 -o2;
//            }
//        });
////        Iterator iterator = arrayList.iterator();
////        while (iterator.hasNext()){
////            if (iterator.next().equals(iterator.hasNext())){
////               iterator.remove();
////            }
////        }
//
//        while (!arrayList.isEmpty()){
//            int i = 0;
//            if (Objects.equals(arrayList.get(i),arrayList.get(i + 1))){
//                arrayList.remove(0);
//                arrayList.remove(1);
//            }else {
//                if (Objects.equals(arrayList.get(i), arrayList.get(i + 1))) {
//                   break;
//                }
//                return false;
//            }
//        }
//        arrayList.forEach(o -> System.out.println(o));
//        return  true;
//    }
//}
package Pre.Exam;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiFunction;

public class Exam02 {

    public static void main(String[] args) {
        // 给定两个字符串 `s` 和 `t` ，编写一个函数来判断 `t` 是否是 `s` 的字母异位词。
        String s = "abcdefgd";
        String t = "abcdefd";
//        HashMap<Character, Integer> sHashMap = getHashMap(s);
//        HashMap<Character, Integer> tHashMap = getHashMap(t);
//        System.out.println(sHashMap.equals(tHashMap));
        Character[] characters = new Character[]{'k', 'l', 's'};
        char[] sCharArray = s.toCharArray();
        char[] tCharArray = t.toCharArray();
        System.out.println();
        String[] strings = s.split("");
        String[] tStrings = t.split("");

        List<char[]> list2 = Arrays.asList(sCharArray);
        List<Character> list1 = Arrays.asList(characters);
        // Arrays.asList(strings) 返回的List对象是在 Arrays 里面定义的一个内部类 没有重写 removeAll
        List<String > list = new ArrayList<>(Arrays.asList(strings));
        List<String > tList = new ArrayList<>(Arrays.asList(tStrings));
        list.removeAll(tList); // 删除两个集合的交集
        System.out.println(list.size() == 0); //

//        Arrays.sort(sCharArray);
//        Arrays.sort(tCharArray);
//        System.out.println(Arrays.equals(sCharArray, tCharArray));

    }

    public static HashMap<Character, Integer> getHashMap(String s) {
        HashMap<Character, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            hashMap.compute(s.charAt(i), new BiFunction<Character, Integer, Integer>() {
                @Override
                public Integer apply(Character character, Integer integer) {
                    return integer == null ? 1 : integer + 1;
                }
            });
        }
        return hashMap;
    }
}
